package com.iretailer.report.analyze.flow.device;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iretailer.report.analyze.annotation.AnalyzeClass;
import com.iretailer.report.analyze.commonModel.PassengerFlowModel;
import com.iretailer.report.analyze.commonUtil.ResponeResultType;
import com.iretailer.report.analyze.flow.CommonFunc;
import com.iretailer.report.analyze.flow.Flow;
import com.iretailer.report.analyze.flow.Xml2Data;
import com.iretailer.report.util.StringUtil;
import io.netty.buffer.ByteBuf;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Auther: xjw
 * @Date: 2019/3/10 10:59
 * @Description:
 */
@AnalyzeClass
@Component
public class Nec extends Flow implements Xml2Data {

    @Value("${netty.path.nec}")
    private String nec;

    @Override
    public String[] analyzePath() {
        if (StringUtil.notEmpty(nec)) {
            return nec.split(",");
        } else {
            return new String[]{"/nec"};
        }
    }

    @Override
    public PassengerFlowModel transformation(String context, Map<String, Object> paramsMap) {
        return CommonFunc.transformation(context, this);
    }

    @Override
    public void deviceTypeDiff(JSONObject object, PassengerFlowModel flow) {
        flow.setChannelCloseType(ResponeResultType.CFLType.CLOSE);
        flow.setDeviceType("nec");
        flow.setSiteName((String) object.get("SiteName"));
        flow.setDeviceName((String) object.get("DeviceName"));
    }

    @Override
    public void dataDiff(JSONArray reports, PassengerFlowModel flow) {
        CommonFunc.switchFuncNec(reports, flow);
    }

}
